package com.ruoyi.business.controller;

import com.ruoyi.business.domain.Exam;
import com.ruoyi.business.domain.UserExam;
import com.ruoyi.business.domain.UserExamQuestion;
import com.ruoyi.business.domain.bo.ExamBo;
import com.ruoyi.business.domain.bo.UserExamBo;
import com.ruoyi.business.domain.bo.UserExamQuestionBo;
import com.ruoyi.business.domain.vo.ExamVo;
import com.ruoyi.business.service.IExamService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * @author 最爱喝兽奶
 * @create 2022/8/10
 **/
@Api("考试的控制器")
@RestController
@RequestMapping("/business/exam")
public class ExamController extends BaseController {

    @Autowired
    private IExamService examService;

    @ApiOperation("考试信息的插入方法")
    @PostMapping
    public AjaxResult add(@RequestBody ExamBo bo) {
        examService.insertExam(bo);
        return AjaxResult.success();
    }

    @ApiOperation("根据考试id查询考试详情")
    @GetMapping("/{id}")
    public AjaxResult getExamInfo(@PathVariable("id") String id) {
        ExamVo examVo = examService.queryExamVo(id);
        return AjaxResult.success(examVo);
    }

    @ApiOperation("分页查询所有的考试信息")
    @GetMapping("/list")
    public TableDataInfo<ExamVo> list(ExamBo bo) {
        TableDataInfo<ExamVo> result = examService.selectExamByPage(bo);
        return result;
    }


    @ApiOperation("分页查询当前学生的考试信息")
    @GetMapping("/stu/list")
    public TableDataInfo<ExamVo> queryStuExam(UserExamBo bo) {
        TableDataInfo<ExamVo> result = examService.queryStuExamByPage(bo);
        return result;
    }

    @ApiOperation("提交考试")
    @PostMapping("/submit")
    public AjaxResult submitExam(@RequestBody List<UserExamQuestionBo> bos) {
        examService.submitExam(bos);
        return AjaxResult.success();
    }

    /**
     * 分页查询课程关联对象
     */
    @ApiOperation("查询课程关联对象")
    @GetMapping("/refTable")
    public AjaxResult refTable(@NotEmpty(message = "关联对象不能为空") String refColumn, Integer pageSize, Integer currentPage, String filterContent, String filterId) {
        return AjaxResult.success(examService.selectRefTableByName(refColumn, pageSize, currentPage, filterContent, filterId));
    }


}
